/**
 * 这个页面生成动态路由
 * 路由权限通过路由守卫控制，生成路由时不与后端方法耦合，根据文件路径生成全部路由
 * */
import layouts from './layouts'
import RenderByRoute from '../components/RenderByRoute.vue'
import ErrorNotFound from "../components/ErrorNotFound.vue";

/**
 * 根据布局容器生成路由
 */
function createRoutesByLayouts() {
    const records = []
    for (const layoutName in layouts) {
        // records.push({
        //   path: `/${layoutName}`,
        //   component: layouts[layoutName],
        //   children: [
        //     { path: 'lowCodePage/:viewCode', component: RenderByViewCode },
        //   ]
        // })
        records.push({
            path: `/${layoutName}`,
            component: layouts[layoutName],
            children: [
                {path: 'route/:path+', component: RenderByRoute},
            ]
        })
    }
    return records
}

const routes = [
    {
        path: '/',
        redirect: '/layout/route/test',
    },
    ...createRoutesByLayouts(),
    /*{
        path: '/code/:viewCode',
        component: RenderByViewCode
    },*/
    {
        path: '/route/:path+',
        component: RenderByRoute
    },
    {
        path: '/:catchAll(.*)*',
        component: ErrorNotFound,
    },
];

export default routes;
